package com.base.commonlib.base;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.base.commonlib.R;
import com.base.commonlib.http.utils.SnackBarUtil;
import com.base.commonlib.utils.PbDialog;
import com.base.commonlib.utils.PbMsgDialog;


/**
 * Date：2019/4/10 下午7:17
 * Creator：arvin
 * Des：
 */

public abstract class CBaseActivity extends BaseSimpleActivity {
    protected PbDialog mPbDialog;
    protected PbMsgDialog mPbMsgDialog;
    protected Toolbar mToolbar;
    private TextView mTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            mToolbar = findViewById(R.id.bar);
            mTitle = findViewById(R.id.title);
            mToolbar.setTitle("");
            setSupportActionBar(mToolbar);
        }catch (Exception e)
        {

        }

        init();
        start();
    }

    @Override
    protected void showPb() {
        if (mPbDialog == null) {
            mPbDialog = new PbDialog(mContext);
            mPbDialog.setCancelable(false);
        }
        mPbDialog.show();
    }

    @Override
    protected void hidePb() {
        if (mPbDialog != null) {
            mPbDialog.dismiss();
        }
    }

    @Override
    protected void showError() {
        SnackBarUtil.showMsg(mRootBinding.getRoot(), "出错了");
    }

    @Override
    protected void showPb_mes(String mes) {
        if (mPbMsgDialog == null) {
            mPbMsgDialog = new PbMsgDialog(mContext,mes);
            mPbMsgDialog.setCancelable(false);
        }else
        {
            mPbMsgDialog.setMsg(mes);
        }
        mPbMsgDialog.show();
    }

    @Override
    protected void hidePb_mes() {
        if (mPbMsgDialog != null) {
            mPbMsgDialog.dismiss();
        }
    }

    protected void setBarTitle(String tittle)
    {
        try {
            mTitle.setText(tittle);
        }catch (Exception e)
        {

        }

    }

    protected void setBackNavigation()
    {
        try {
            mToolbar.setNavigationIcon(R.drawable.ic_title_back);
            mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }catch (Exception e)
        {

        }

    }

    protected abstract void init();

    protected abstract void start();

}
